//
// Created by chaofengan on 23-8-29.
//

#ifndef UNTITLED6_PROCESS_USING_TABLE_H
#define UNTITLED6_PROCESS_USING_TABLE_H
typedef int pid_t;
#define NO_AMOUNT -1
#include "unordered_map"
#include "vector"
#include "single_memory_using_record.h"

class process_using_table{
private:
    std::unordered_map<pid_t,std::vector<single_memory_using_record> > using_table;
    std::unordered_map<int,pid_t> position_to_pid_table;
public:
    int find_position_host(int position);
    bool if_position_is_free(int position);
    void delete_using(pid_t pid,int position);
    void add_using(single_memory_using_record &a_log);

    int get_amount_by_pid_and_position(pid_t pid,int position){
        std::vector<single_memory_using_record> v1 = using_table[pid];
        for(auto iter = v1.begin();iter != v1.end();iter++){
            if(iter->using_position == position){
                return iter->using_amount;
            }
        }
        return NO_AMOUNT;
    }
};
#endif //UNTITLED6_PROCESS_USING_TABLE_H
